package cn.agiledata.bank.myspace.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.agiledata.bank.account.service.IAccountConst;
import cn.agiledata.bank.common.util.WeatherUtil;
import cn.agiledata.bank.hibernateBean.Account;
import cn.agiledata.bank.myspace.service.IMySpaceService;
import com.vnv.infrastructure.action.IPBBaseAction;
import com.vnv.infrastructure.action.IPBBaseDynaForm;
import com.vnv.infrastructure.exception.IPBException;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class AbstractMySpaceAction extends IPBBaseAction implements IAccountConst {
	protected IMySpaceService getMySpaceService() throws IPBException {
		return (IMySpaceService) IPBAppFactory.getObj(IMySpaceService.MGR_ID);
	}
	
	/**
	 * 得到账户Id
	 * @param request
	 * @return
	 */
	protected String getAccountId(HttpServletRequest request) throws IPBException {
		return String.valueOf(WeatherUtil.getAccountIdFromSession(request));
	}
	
	/**
	 * 得到账户
	 * @param request
	 * @return
	 */
	protected Account getAccount(HttpServletRequest request) throws IPBException {
		return getMySpaceService().getAccount(getAccountId(request));
	}


	/**
	 * 
	 * @param form
	 * @return
	 */
	protected Map getMap(ActionForm form){
		IPBBaseDynaForm dynaForm = (IPBBaseDynaForm) form;
		return  new HashMap(dynaForm.getMap());
	}
	
	//成功页面
	protected final String SUCCESS = "success";
	//失败页面
	protected final String FAILURE = "failure";
	
	/**
	 * 设置返回码
	 * @param request
	 * @param returnCode
	 */
	protected void setReturnCode (HttpServletRequest request,String returnCode,String actionName) {
		request.setAttribute(RQ_RETURNCODE, returnCode);
		request.setAttribute(RQ_ACTIONNAME, actionName);
	}
	/**
	 * 
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub

		WeatherUtil.setPageModual(mapping, request);
		return super.execute(mapping, form, request, response);
	}
	
	
}
